/* JavaLog - package tracker 
 * 
 * Copyright (C) 2009  Allyson Lima, Diego Pedro, Victor Freire
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software 
 * Foundation, either version 3 of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this 
 * program.  If not, see <http://www.gnu.org/licenses/>.
 */

package br.edu.ufcg.ccc.javalog.model;

/**
 * Class for retrieving model objects.
 * 
 * @author Allyson Lima, Diego Pedro, Victor Freire
 * @version 03/12/09
 */
public class Data {
	/**
	 * The singleton's instance.
	 */
	private static Data instance;
	private Headquarters headquarters;

	/**
	 * Return headquarters model.
	 */
	public Headquarters getHeadquarters() {
		if (headquarters == null) {
			// Create default HQ
			try {
				Address address0 = new Address("Nordeste", "Paraiba", "Campina Grande", "Bodocongo", "59021-666", "Aprigio Veloso", "666");
				headquarters = new Headquarters("Matriz", address0, true);
				
				Address address1 = new Address(Address.getValidRegions().get(0), "Georgia", "New Atlanta", "Sector 11", "15784-542", "Aprigio Veloso", "15784542");
				Address address2 = new Address(Address.getValidRegions().get(0), "Faerun", "Amn", "Market District", "15784-542", "Waukeen Promenade", "15784542");
				Franchise franchise1 = new Franchise("SShock", address1, true);
				Franchise franchise2 = new Franchise("BGate", address2, true);
				headquarters.addFranchise(franchise1);
				headquarters.addFranchise(franchise2);
				
				headquarters.createPackage(new PackageExpress(address1, address2, franchise1, franchise2));
				headquarters.createPackage(new PackageNormal(address0, address2, headquarters, franchise2));
				headquarters.createPackage(new PackageOneDay(address2, address1, franchise2, franchise1));
			} catch (Exception ex) {
				System.err.println("Should not have thrown an exception");
				ex.printStackTrace();
				System.exit(1);
			}
		}
		return headquarters;
	}

	/**
	 * Only the singleton can construct WindowManager objects.
	 */
	private Data() {

	}

	/**
	 * Returns the unique instance of this singleton.
	 */
	public static Data getInstance() {
		if (instance == null)
			instance = new Data();
		return instance;
	}
}
